Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

base-task

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-task

base plugin that provides a very thin wrapper around <https://github.com/doowb/composer> for adding task methods to your application.

  • 0.4.5
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

base-task NPM version NPM downloads Build Status

base plugin that provides a very thin wrapper around https://github.com/doowb/composer for adding task methods to your application.

You might also be interested in base-watch.

Install

Install with npm:

$ npm install base-task --save

Usage

var Base = require('base-methods');
var tasks = require('base-task');
Base.use(tasks());

var base = new Base();
base.task('foo', function(cb) {
  console.log('this is foo!');
  cb();
});
base.task('bar', function(cb) {
  console.log('this is bar!');
  cb();
});

base.build(['foo', 'bar'], function(err) {
  // this is foo!
  // this is bar!
  console.log('done!');
});

See the composer documentation for more details, or to create bug reports related to running or registering tasks.

API

.task

Register a task

Params

  • name {String}: Task name to register (tasks are cached on app.tasks)
  • dependencies {String|Array|Function}: String, list or array of tasks.
  • callback {Function}: Function to be called when the task is executed. Task functions should either return a stream or call the callback to let composer know when the task is finished.

Examples

Register a task.

app.task('default', function() {
  // return the stream to signal "done"
  return app.src('pages/*.hbs')
    .pipe(app.dest('dist'));
});

Register a task with dependencies (other tasks to run before executing the task):

app.task('site', ['styles'], function() {
  return app.src('pages/*.hbs')
    .pipe(app.dest('dist'));
});

app.task('default', ['site']);

Get a task

var task = app.task('site');

.build

Run a task or array of tasks.

Example

app.build('default', function(err, results) {
  if (err) {
    console.error(err);
    return;
  }
  console.log(results);
});

.series

Compose task or list of tasks into a single function that runs the tasks in series.

Params

  • tasks {String|Array|Function}: List of tasks by name, function, or array of names/functions.
  • returns {Function}: Composed function that may take a callback function.

Example

app.task('foo', function(cb) {
  console.log('this is foo');
  cb();
});

var fn = app.series('foo', function(cb) {
  console.log('this is bar');
  cb();
});

fn(function(err) {
  if (err) return console.error(err);
  console.log('finished');
});
//=> this is foo
//=> this is bar
//=> finished

.parallel

Compose task or list of tasks into a single function that runs the tasks in parallel.

Params

  • tasks {String|Array|Function}: List of tasks by name, function, or array of names/functions.
  • returns {Function}: Composed function that may take a callback function.

Example

app.task('foo', function(cb) {
  setTimeout(function() {
    console.log('this is foo');
    cb();
  }, 500);
});

var fn = app.parallel('foo', function(cb) {
  console.log('this is bar');
  cb();
});

fn(function(err) {
  if (err) return console.error(err);
  console.log('finished');
});
//=> this is bar
//=> this is foo
//=> finished

Events

The following events are emitted by composer. See the composer docs for more details

starting

Emitted when a build is starting.

app.on('starting', function(app, build) {});

The event emits 2 arguments:

  1. the current instance of composer as the app and
  2. An object with build runtime information:
  • .date: an object with the .start time as a Date object.
  • .hr: an object with the .start time as an hrtime array.

finished

Emitted when a build is finished.

app.on('finished', function(app, build) {});

The event emits 2 arguments:

  1. app: instance of composer
  2. build: an object with build runtime information:
  • .date: object with .start and .end properties, with staring and ending times of the build as Date objects.
  • .hr: object with .start, .end, .duration, and .diff properties with timing information calculated using process.hrtime

error

Emitted when an error occurrs during a build.

app.on('error', function(err) {});

task:starting

Emitted when a task is starting.

app.on('task:starting', function(task, run) {});

task:finished

Emitted when a task has finished.

app.on('task:finished', function(task, run) {});

task:error

Emitted when an error occurrs while running a task.

app.on('task:error', function(err) {});

History

v0.3.0

  • Bumped composer to v0.11.0, so the .watch method is no longer included by default. To add .watch, use the base-watch plugin.

Other base plugins you might be interested in:

  • base-cli: Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a… more | homepage
  • base-generators: Adds project-generator support to your base application. | homepage
  • base-option: Adds a few options methods to base, like option, enable and disable. See the readme… more | homepage
  • base-plugins: Upgrade's plugin support in base applications to allow plugins to be called any time after… more | homepage
  • base-store: Plugin for getting and persisting config values with your base-methods application. Adds a 'store' object… more | homepage
  • base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with [verb][]:

$ npm install verb && npm run docs

Or, if [verb][] is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v0.9.0, on May 11, 2016.

Keywords

FAQs

Package last updated on 15 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc